package ch.bfh.abcmmh.view.detailview.streets.entranceramp;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import ch.bfh.abcmmh.controller.operating.LogicController;
import ch.bfh.abcmmh.view.GUIController;

public class GrassStreetCover extends JPanel implements Observer {

	private static final long serialVersionUID = 1L;

	private int ypos;
	private GUIController guiController;
	private int grasslength, height, noGrass;
	private Image  image;

	public GrassStreetCover(GUIController guiController, int ypos, int streetPanelHeight) {
		this.ypos = ypos;
		this.guiController = guiController;
		noGrass = LogicController.ENTRANCERAMPLENGTH+ LogicController.ZONELENGTH;
		this.grasslength = guiController.getLogicalStreetLenth()-noGrass;
		this.height = streetPanelHeight;
		Dimension size = new Dimension(grasslength, height);
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		image = new ImageIcon("resources/grass.jpg").getImage();
		setLayout(null);
		this.setLocation(noGrass +20, ypos);
		setVisible(true);
		setOpaque(true);

	}

	@Override
	public void paint(Graphics g) {
//		g.setColor(Color.MAGENTA);
//		g.fillRect(0, 0, grasslength, height);
		int max = guiController.getLogicalStreetLenth()/1400;
		for (int i = 0; i < (max+1); i++) {
			g.drawImage(image, i*1400, 0, null);			
		}
	  
	}
	
	@Override
	public void update(Observable o, Object arg) {
		int scopepos = guiController.getDetailPosition();
		this.setLocation((noGrass+20)-scopepos, ypos);
		repaint();
	}

}
